#ifndef MESSAGEQUEUE_H
#define MESSAGEQUEUE_H

#include <vector>
#include "Mutex.h"

using namespace std;

typedef struct Message {
	int what;
	int arg1;
	int arg2;
} Message;

class MessageQueue {
public:
	MessageQueue();
	~MessageQueue();

	void post(Message &msg);
	int get(Message &msg);
	int size(){return m_Queue.size();}
	bool isEmpty(){return m_Queue.size() == 0 ? true : false;};
	void wait(){
		AutoLock lock(&m_Cond); 
		m_Cond.wait();
	}
	void notify(){m_Cond.notify();}
	void clear() {
		m_Queue.clear();
	}
	void abort() {
		m_AbortRequest = true;
		notify();
	}

protected:
	vector<Message> m_Queue;
	Condition m_Cond;
	bool m_AbortRequest;
};

#endif